// Drummer
// by Andrea Bianchi
// andreabianchi.alsoplantsfly.com

/*
 Copyright (C) 2009, Andrea Bianchi
 
 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version 2
 of the License, or (at your option) any later version.
 
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/


#ifndef __DRUM_MANAGER__H__
#define __DRUM_MANAGER__H__

#include "global.h"
#include "circle.h"
 
namespace DS
{
	class DrumManager 
	{
	public:
		static DrumManager* getInstance();

		void selectDrum (const Coord& pos);
		inline void deselectDrum () { selected_=NO_SELECTION; }
		inline bool hasSelected () const { return selected_!=NO_SELECTION; }

		void beginCreateDrum (const Coord& pos);
		void endCreateDrum ();
		inline bool isEditMode() const {return editMode_;}
	
		void removeCircle (u8 index);
		void removeSelectedCircle ();

		void press();
		void drag();
		void release();

		void moveDrumsTo (const Coord& pos);
		void editDrumSize (const Coord& pos);
		void draw();


	private:

		DrumManager();
		~DrumManager(){}
		
		void sortDrums ();
		void swapCircles (u8 i, u8 j);
		bool isHiHat (u8 circleNumber) const;
		void finalizeCircle();

		void selectBackground();

		DrumPart getDrumPart(u8 circleNumber) const;
		void selectCircleColor(u8 circleNumber);
		void selectAllCirclesColor();

		void selectSelectedCircleColor();
		DrumPart getSelectedCircleDrumPart() const;

		void hitCircle();
		void releaseCircle();

		static const u8 drumArraySize_= 9;
		static const u8 minCircleSize_= 10;
		
		Circle circles_[drumArraySize_];
		u8 drums_, selected_;
		bool editMode_;
		Coord grab_;
	};
}

#endif __DRUM_MANAGER__H__